package logic

import (
	"context"

	"probe-scheduler/internal/svc"
	pb "probe-scheduler/pb/scheduler"

	"github.com/zeromicro/go-zero/core/logx"
)

type QueryTaskLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewQueryTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryTaskLogic {
	return &QueryTaskLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *QueryTaskLogic) QueryTask(in *pb.QueryTaskRequest) (*pb.QueryTaskResponse, error) {
	// 查询任务
	tasks, total := l.svcCtx.Scheduler.QueryTasks(in.TaskId, in.Status)

	return &pb.QueryTaskResponse{
		Base: &pb.CommonResponse{
			Success: true,
		},
		Tasks: tasks,
		Total: int32(total),
	}, nil
}
